<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page contentType="text/html; charset=UTF-8" %>
<%@include file="/sys_include.jsp"%>

<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>系统管理</title>

   <!-- jquery -->
   <script type="text/javascript" src="jeasyui/jquery.min.js"></script>
   
   <!-- jeasy ui -->
   <link rel="stylesheet" type="text/css" href="jeasyui/themes/default/easyui.css">
   <link rel="stylesheet" type="text/css" href="jeasyui/themes/icon.css">
   
   <script type="text/javascript" src="jeasyui/jquery.easyui.min.js"></script>
   <script type="text/javascript" src="jeasyui/locale/easyui-lang-zh_CN.js"></script>
   
   <!-- jqgrid 引入文件，语言文件需要在之前加载 -->
   <link rel="stylesheet" type="text/css" href="jqgrid/css/ui.jqgrid.css">
   
   <script type="text/javascript" src="jqgrid/js/i18n/grid.locale-cn.js"></script>
   <script type="text/javascript" src="jqgrid/js/jquery.jqGrid.min.js"></script>
   
   <!-- 可选jqueryui主题 -->
   <!-- <link rel="stylesheet" type="text/css" href="jqueryui/css/start/jquery-ui-1.9.0.custom.css"> -->
   <link rel="stylesheet" type="text/css" href="jqueryui/css/custom-theme/jquery-ui-1.9.1.custom.css">
   
</head>

<body class="easyui-layout">
   <div data-options="region:'north',border:false" style="height:98px; overflow:hidden; background:#0da8d7;">
      <img src="images/head.jpg" width="1184" height="98">
   </div>
   
   <div data-options="region:'south',border:false"
        style="height:30px;padding:5px; overflow:hidden; color:#fff; text-align:center;background:#0696dd;">版权所有
   </div>
   
   <div data-options="region:'west',split:true" title="系统菜单" style="width:280px;padding1:1px;">
      <!--<div class="easyui-accordion" data-options="fit:true,border:false"></div>-->
      <div title="系统菜单" data-options="fit:true,border:false,selected:true" style="padding:10px;">
         <ul id="frame_menu_tree" class="easyui-tree"></ul>
      </div>
   </div>
   
   
   <div data-options="region:'center'"  style="overflow:hidden;">
      <div id="frame_home_page_content" class="easyui-layout" data-options="fit:true"> 
         <div data-options="region:'north',border:false" style="height:28px; overflow:hidden">
         
            <div class="" style="width:100%; height:32px;  background:#eee;" data-options="fit:true">
               <div class="panel layout-panel layout-panel-west" style="left: 0px; top: 0px; width:50%; padding:8px;">
                  <div class="demo-tip icon-tip"></div>
                  <div>
                     <b id="idx_user_name_xs">当前登录用户 ：<%=web_login_username%></b></div>
               </div>
               <div class="panel layout-panel layout-panel-east " style="right:0px; top: 0px; width:50%; text-align:right;padding:4px;">
                  <a class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-cancel'"
                     href="javascript:g_exit_system()">退出系统</a>
                  <!--
                  <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">帮 助</a>
                  -->
               </div>
            </div>
         </div>
       
         <div data-options="region:'center'">
            <div id="frame_tab_content" class="easyui-tabs" data-options="fit:true,border:false">
               <div title="首页" style="padding:10px;" data-options="tools:[{iconCls:'icon-mini-refresh'}],closable:false,fit:true,href:''"></div>
            </div>
         </div>
      </div>
   </div>
   
   <!-- 弹出菜单：关闭所有tab -->
   <div id="frame_close_all" class="easyui-menu" style="width:120px;">
      <div onclick="removeAllTab()" data-options="iconCls:'icon-remove'">关闭所有页面</div>
   </div>
   
</body>



<script type="text/javascript">
var g_tab_index = 0;
var g_max_open_tab = 32;

function createUIWindow(win_obj, modal_flag, win_width, win_height)
{
   $("#" + win_obj).window({  
      width: win_width,  
      height: win_height,
      modal: modal_flag,
      collapsible : false,
      minimizable : false,
      resizable : false,
      closed : false
   });
}

function openUIWindow(win_obj, modal_flag, win_width, win_height)
{
   $("#" + win_obj).window({  
      width: win_width,  
      height: win_height,
      modal: modal_flag,
      collapsible : false,
      minimizable : false,
      resizable : false,
      closed:true
   });
   
   $("#" + win_obj).window('open');
}

function closeUIWindow(win_obj)
{
   /*
   $("#" + win_obj).window({  
      width: 600,  
      height: 400, 
      modal: true,
      collapsible : false,
      minimizable : false,
      resizable : false,
      closed: true
   });
   */
   
   $("#" + win_obj).window({  
      modal: true,
      closed: true
   });
   
   $("#" + win_obj).window('close');
}

function openUIDialog(win_obj, modal_flag, win_width, win_height)
{
   $("#" + win_obj).dialog({  
      width: win_width,  
      height: win_height,
      modal: modal_flag,
      collapsible : false,
      minimizable : false,
      resizable : false,
      closed:true
   });
   
   $("#" + win_obj).dialog('open');
}

function closeUIDialog(win_obj)
{
   /*
   $("#" + win_obj).window({  
      width: 600,  
      height: 400, 
      modal: true,
      collapsible : false,
      minimizable : false,
      resizable : false,
      closed: true
   });
   */
   
   $("#" + win_obj).dialog({  
      modal: true,
      closed: true
   });
   
   $("#" + win_obj).dialog('close');
}


function clickTreeNode(tree_obj, tree_node)
{
   var leaf_flag = $("#" + tree_obj).tree('isLeaf', tree_node.target);
   if(leaf_flag)
   {
      openFrameTab('frame_tab_content', tree_node.text, tree_node.attributes.url);
   }
   
   return ;
}

function openFrameTab(tabs_obj, tab_title, tab_url)
{
   //根据tab标题判断是否已经打开，不存在则打开新的tab，存在则设置为当前
   var exist_tab = $("#" + tabs_obj).tabs('exists', tab_title);
   if(exist_tab == false)
   {
      if(g_tab_index >= g_max_open_tab)
      {
         alert('最多打开9个页面，请关闭暂时不用的页面!');
         return ;
      }
      
      $('#' + tabs_obj).tabs('add',{  
         title: tab_title,
         href: tab_url,
         selected: true,
         closable:true,
         fit:true,
         tools:[{  
             iconCls:'icon-mini-refresh',
             handler:function()
             {  
                refreshTab(tab_title, tab_url);  
             }
         }]  
      });
      
      //var tab_obj = $('#frame_tab_content').tabs('getTab', tree_node.text);
      //tab_index = $('#frame_tab_content').tabs('getTabIndex', tab_obj);
      g_tab_index++;
   }
   else
   {
      $("#" + tabs_obj).tabs('select', tab_title);
      refreshTab(tab_title, tab_url);
   }
   
   return ;
}

//关闭所有tab，仅剩下首页
function removeAllTab()
{
   for(var i=g_tab_index; i>0; i--)
   {
      $('#frame_tab_content').tabs('close', i);
   }
}

function closeCurrentFrameTab()
{
   var select_tab_panel = $('#frame_tab_content').tabs('getSelected');
   var select_tab = select_tab_panel.panel('options').tab; 
   var tab_title = select_tab_panel.panel('options').title;
   
   //关闭tab
   $("#frame_tab_content").tabs('close', tab_title);
   //$('#frame_tab_content').tabs('close', i);
}

//用指定的title、href刷新当前tab
function refreshTab(tab_title, tab_url)
{
   //获取对应的panel
   var select_tab_panel = $('#frame_tab_content').tabs('getSelected');
   
   //var tabs_options = $('#frame_tab_content').tabs('options');
   //获取tab
   var select_tab = select_tab_panel.panel('options').tab; 
   
   var tab_href = select_tab_panel.panel('options').href;
   var tab_title = select_tab_panel.panel('options').title;
   
   select_tab_panel.panel('refresh', tab_url);
   
   //alert(select_tab_panel.panel('options').width);
   //var tab_width = select_tab_panel.panel('options').width;
   
   //alert('refreshTab - ' + title);
   //alert(tab_width);
   
   /*
   alert(tab_href);
   $('#frame_tab_content').tabs('update', {
      tab: select_tab,
      options: {
         href: tab_href
      }
   });
   */
}

//菜单树
$('#frame_menu_tree').tree({
   onClick: function(node)
   {
      clickTreeNode('frame_menu_tree', node);
   }
});

//关闭时更新计数器
$('#frame_tab_content').tabs({
   onBeforeClose: function(title)
   {
      //return confirm('Are you sure you want to close ' + title);
      g_tab_index--;
      //alert('close, tab size[' + g_tab_index + ']');
   }
});

//显示弹出菜单
$('#frame_tab_content').tabs({
   onContextMenu: function(e, title,index)
   {
      e.preventDefault();
      // display context menu
      $('#frame_close_all').menu('show', {
         left: e.pageX,
         top: e.pageY
      });
   }
});

function getFrameTabWidth()
{
   var select_tab_panel = $('#frame_tab_content').tabs('getSelected');
   var tab_width = select_tab_panel.panel('options').width;
   
   return tab_width;
}


function initFrameData()
{
   var req_param = new Object();
   req_param.user_id = '<%=web_login_userid%>';
   
   $.ajax(
   {
      type : "POST",
      async : true,
      url : "./system/Menu/getMenuData.do",
      dataType : "json",
      data :
      {
         req_param : JSON.stringify(req_param)
      },
      contentType : "application/x-www-form-urlencoded; charset=UTF-8",
      success : function(json)
      {
         if(json.success)
         {
            //$('#frame_menu_tree').tree({});
            $('#frame_menu_tree').tree('loadData', json.msg);
         }
         else
         {
            alert('加载数据错误，请重试！');
         }
      }
   });
   
   return ;
}

//加载select数据
function g_setSelectOption(select_id, option_set)
{
   var option_str;
   var option_value, option_text, option_state;

   $("#" + select_id).html('');
   for ( var i = 0; i < option_set.length; i++)
   {
      option_state = '';
      option_value = option_set[i].id;
      option_text = option_set[i].text;
      option_str = "<option value=\"" + option_value + "\" " + option_state + " >" + option_text + "</option>";

      //alert(option_str);
      $("#" + select_id).append(option_str);
   }

   return;
}

function g_load_combobox_static_data(combobox_obj, data_index)
{
   var req_param = new Object();
   req_param.data_type_index = data_index;
   
   $('#' + combobox_obj).combobox({
      url: '',
      valueField: 'id',  
      textField: 'text',
      editable: false
   });
   
   $.ajax(
   {
      async : false,
      type : "POST",
      url : "system/StaticData/getStaticData.do",
      dataType : "json",
      data :
      {
         req_param : JSON.stringify(req_param)
      },
      success : function(json)
      {
         if (json.success)
         {
            $('#' + combobox_obj).combobox('loadData', json.msg);
         }
         else
            alert('error');
      }
   });
}


function g_combotree_isleaf(combotree_obj)
{
	var tree_obj = $('#' + combotree_obj).combotree('tree');
	var tree_node = tree_obj.tree('getSelected');
	if(tree_node == null)   return false;
	
	var leaf_flag = tree_obj.tree('isLeaf', tree_node.target);
	
	return leaf_flag;
}

function g_exit_frame()
{
   confirm("您确定要退出本系统?", exit);
}
 
function g_exit_system()
{
   if(confirm("您确定要退出本系统?"))
   {
      location = '<%=request.getContextPath()%>/j_spring_security_logout';
   }
   
   return ;
}


$(function()
{
   initFrameData();
   
   refreshTab('首页', 'sys_test.jsp');
});


</script>


</html>